/*! \brief Multi Sprites handler class.
*
* Inherited class from sprite allowing basic animations.
*/
#ifndef __ANIMATED_SPRITE__
#define __ANIMATED_SPRITE__

#include <allegro.h>

#include "sprite.h"
#include "consts.h"

class AnimatedSprite : public Sprite {
  public:
    /*! \brief Class constructor.
    *
	  * A basic constructor initializing the memory.
	  */
    AnimatedSprite();
    /*! \brief Class destructor. */
    ~AnimatedSprite();
    /*! \brief Destroy every bitmap.
    *
    */
    void __free();
    /*! \brief Animates the sprite.
    *
    * This change the Sprite and replace it with the next frame of the sequence.
    * \return status of the current frame
    */
    int __updateAnimation(int debug = 0);
    /*! \brief Replace a sequences's frame with another bitmap.
    *
    * \param nres a bitmap resource
    * \param sequence: Sequence ID
    * \param frame: Frame ID
    * \param duration number of frames the animation will last
    */
    void __addBitmap(BITMAP * nres, int sequence, int frame, int duration);
    /*! \brief Change the bounding box for a specified frame.
    *
    * \param nbb is BoundingBox object
    * \param sequence: Sequence ID
    * \param frame: Frame ID
    */
    void __addBoundingBox(BoundingBox nbb, int sequence, int frame);
    /*! \brief Setup a new/existing sequence.
    *
    * \param sequence: Sequence ID
    * \param l is the length of the animation
    * \param seqArr[] contains the frames ID
    * \param seqTimeArr[] contains the frames duration
    */
    void __setSequence(int sequence, int l, int seqArr[MAX_SEQUENCE_LENGTH], int seqTimeArr[MAX_SEQUENCE_LENGTH]);
    /*! \brief Returns the current sequence being played.
    *
    * \return integer: Sequence ID
    */
    int __getSequence();    
    /*! \brief Change the displayed animation.
    *
    * \param nseq : Sequence ID
    */
    void __changeSequence(int nseq);
    /*! \brief Reset the animation.
    *
    */
    void __resetSequence();
    /*! \brief Generate the animations using a file.
    *
    * Will create every sequences using a config file (See animation_readme.txt)
    * \param fname is the path of the file to read
    * \param autoBB will generate BoundingBox if set to 1
    */
    void __readFile(const char * fname, int autoBB = 1);
    /*! \brief Attach a status to a specified frame.
    *
    * \param status an integer
    * \param sequence: Sequence ID
    * \param frame: Frame ID
    */
    void __linkStatus(int status, int sequence, int frame);
    /*! \brief Copy The bitmap array
    *
    * \param nPack
    */
    void __copyPack(AnimatedSprite * nPack);
    
  protected:
    /**
    * Bitmap array resource
    */
    BITMAP * _bmpArr[MAX_ANIMATION][MAX_FRAME_PER_ANIMATION];
    
  private:
    BoundingBox _bbArr[MAX_ANIMATION][MAX_FRAME_PER_ANIMATION];
    int _seqArr[MAX_ANIMATION][MAX_SEQUENCE_LENGTH];
    int _seqTimeArr[MAX_ANIMATION][MAX_SEQUENCE_LENGTH];
    int _seqSize[MAX_ANIMATION];
    int _statusArr[MAX_ANIMATION][MAX_FRAME_PER_ANIMATION];
    int _currentAnimation;
    int _currentFrame;
    int _currentFrameTime;
    int _animationPause;  // Won't update if set to 1
};

#endif
